/*
 * @Description:
 * @Version:
 * @Author: Troubadour
 * @Date: 2022-10-11 19:07:06
 * @LastEditors: Troubadour
 * @LastEditTime: 2022-10-11 20:29:12
 */

#ifndef  __BATTERY_H__
#define  __BATTERY_H__

#include "main.h"
#include "adc.h"
#include "kalman.h"

// 是否使用卡尔曼滤波
#define USE_KALMAN_FILTER   1

// 3.3V参考电源，12位ADC
#define ADC_RATIO           (0.0008056640625)
// ADC检测电阻分压值: 10/(10+30)
#define ADC_PARTIAL         (0.25)
#define ADC_ERROR_VALUE     (0.1)
#define BAT_VOLTAGE_MAX     (8.2)
#define BAT_VOLTAGE_MIN     (7.4)
#define BAT_AVERAGE_FILTER_CNT      (10)

typedef struct
{
    uint16_t raw;       // 电池电量原始ADC采样的ADC值
    uint16_t rawArray[BAT_AVERAGE_FILTER_CNT];       // 电池电量原始ADC数据数组
    double voltge;      // 电压值
    uint8_t soc;        // 电压值百分比
}BatteryTypeDef;

extern BatteryTypeDef battery;

void battery_Read(void);
void battery_init(void);


#endif  /* __BATTERY_H__ */
